package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuInfoSaveVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:ahang
 * @create:2022-10-03 13:28
 * @Description:
 */
@Api(tags = "sku接口")
@RequestMapping("admin/product/")
@RestController
public class SkuController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 获取sku分页列表
     * @param ps
     * @param pn
     * @return
     */
    @GetMapping("list/{ps}/{pn}")
    public Result skuList(@PathVariable("ps") Long ps,@PathVariable("pn") Long pn){
        Page<SkuInfo> page = new Page<>(ps,pn);
        Page<SkuInfo> resulte = skuInfoService.page(page);
        return Result.ok(resulte);
    }

    /**
     * sku大保存
     * @return
     */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoSaveVo skuInfoSaveVo){
        skuInfoService.saveSkuInfo(skuInfoSaveVo);
        return Result.ok();
    }

    /**
     * 上架
     * @param skuId
     * @return
     */
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){

        skuInfoService.onSale(skuId);
        return Result.ok();
    }

    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        skuInfoService.canceSale(skuId);
        return Result.ok();
    }
}
